function checkit() {
	var rnt = true;
	if (isblank(document.form1.NAME)) {
		rnt = false;
		alert("请填写办公用品名称");
	} else if (isblank(document.form1.FL)) {
		rnt = false;
		alert("请填写办公用品分类");
	} else if (isblank(document.form1.UNIT)) {
		rnt = false;
		alert("请填写单位");
	}else if (!isinteger(document.form1.WX_NUM)) {
		rnt = false;
		alert("请填写正确的维修数量");
	} else if (!isfloat(document.form1.PRICE)) {
		rnt = false;
		alert("请填写正确的单价");
	}else if (isblank(document.form1.WX_DATE)) {
		rnt = false;
		alert("请填写维修时间");
	} 

	return rnt;
}

/**
 * 保存成功后回调函数
 */
function forwardFunc() {
	Ext.MessageBox.confirm('提示', '要继续增加新的内容吗？', function(e) {
				if (e == "yes") {
					handleRefresh();
				} else {
					window.location.href = context
							+ '/system/tablequery/jsplist.jsp?queryKey=bgyp_wxlist';
				}
			});
}

/**
 * 更新成功后回调函数
 */
function forwardFunc() {
	window.location.href = context
			+ '/system/tablequery/jsplist.jsp?queryKey=bgyp_wxlist';
}

/**
 * 初始化form表单项
 * 
 * @param {}
 *            json
 */
function initFunc(json) {
	
	if (json != null) {
		$('PK_ID').value = json.data.PK_ID;
		$('WX_USERID').value = json.data.WX_USERID;
		$('WX_USERNAME').value = json.data.WX_USERNAME;
		$('NAME').value = json.data.NAME;
		$('FL').value = json.data.FL;
		$('XH').value = json.data.XH;
		$('UNIT').value = json.data.UNIT;
		$('WX_NUM').value = json.data.WX_NUM;
		$('PRICE').value = json.data.PRICE;
		$('WX_DATE').value = formatDate(json.data.WX_DATE
				.substring(0, 8));
		initwordbook4select('fl', json.data.FL, 'FL_NEW', true);
		initTable('APP_BGYP_BM', json.data.BMB_ID, 'single' , function(e){initZBFunc(e);});
	}else {
		initwordbook4select('fl', '', 'FL_NEW', true);
	}
}

function bgyp_bm(json){
		
	if (json != null){
		$('NAME').value = json.get("NAME");
		$('BMB_ID').value = json.get("PK_ID");
		$('FL').value = json.get("FL");
		$('XH').value = json.get("XH");
		$('UNIT').value = json.get("UNIT");
		$('PRICE').value = json.get("PRICE");
		$('BMB_KCNUM').value = json.get("KC_NUM");
		$('FL').value = json.get("FL");
		$('FL_NEW').value = json.get("FL");
		
	}
}

function updateZB(obj){
	
	var id=document.form1.BMB_ID.value;
	var kcnum = document.form1.BMB_KCNUM.value*1;
	var wxnum = document.form1.WX_NUM.value*1;
	var dq_kcnum=0;
	var params = {};
	params.PK_ID = id;
	if(obj=="add"){
		 dq_kcnum= kcnum-wxnum;
		if(dq_kcnum<0){
			dq_kcnum = 0;
		}
		params.KC_NUM = dq_kcnum;
	}else{
		dq_kcnum = (kcnum+wxnum);
		params.KC_NUM = dq_kcnum;
	}
	
	if(checkit()){
		updateColumn('APP_BGYP_BM', 'single', '', params, null,
							function() {
								if(obj=="add"){
									saveTable('APP_BGYP_WX', 'single', '', function(){return checkit();},function(){forwardFunc();});
								}else{
									deleteTable('APP_BGYP_WX', 'single', '', null,function(){forwardFunc();});
								}
									
							});
		
	}
}

function initZBFunc(e){
	if(e!=null){
		$('BMB_ID').value = e.data.PK_ID;
		$('BMB_KCNUM').value = e.data.KC_NUM;
	}
	
}

function renderHeader(value, cellmeta, record, rowIndex, columnIndex, store) {
	var fieldName = cm.getDataIndex(columnIndex);
	if (fieldName == 'BG_DATE') {
		return formatDate(value);
	}else if (fieldName == 'FL') {
		var resultString = '';

		if (value == '1') {
			resultString = '文具类';
		} else if (value == '2') {
			resultString = '设备类';
		} 

		return resultString;
	}else if (fieldName == 'SFKY') {
		var resultString = '正常';

		if (value == '-1') {
			resultString = '停用';
		}

		return resultString;
	} 
	else if (fieldName == 'SP') {
		var str = '<a href="javascript:handleStatus(\'' + record.data['PK_ID']
				+ '\',\'' + record.data['NAME']
				+ '\', \'-1\', \'停用\');">停用</a>';
		
		if (record.data['SFKY'] == '-1') {
			str = '<a href="javascript:handleStatus(\'' + record.data['PK_ID']
					+ '\',\'' + record.data['NAME']
					+ '\', \'0\', \'启用\');">启用</a>';
		}

		return str;
	
	
	}
	return value;
}

